package it.magazzinoCofi.view;

import it.magazzinocofi.settings.ColoriTenarisPrimary;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

public class SchermataPrincipale extends BaseFrame{

	/**
	 * Associazione numero di versione
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * Variabili private
	 * Bottoni
	 */
	private JButton btnInsert = new JButton("Inserisci");
	/**
	 * Field btnModification.
	 */
	private JButton btnModification = new JButton("Modifica");
	/**
	 * Field btnDisplay.
	 */
	private JButton btnDisplay = new JButton("Visualizza");
	/**
	 * Field btnAddUt.
	 */
	private JButton btnAddUt = new JButton("Aggiungi nuovo Utente");
	/**
	 * Field btnPasswordModification.
	 */
	private JButton btnPasswordModification = new JButton("Modifica Password");
	/**
	 * Field btnUpload.
	 */
	private JButton btnUpload = new JButton("Caricamento dati XML");
	/**
	 * Field btnDropUt.
	 */
	private JButton btnDropUt = new JButton("Elimina Utente");
	/**
	 * Label
	 */
	private JLabel lblTenarisIcon = new JLabel("");
	/**
	 * Field lblMgmUt.
	 */
	private JLabel lblMgmUt = new JLabel("Gestione Utenti");
	/**
	 * Field lbWelcome.
	 */
	private JLabel lbWelcome = new JLabel("Benvenuto");
	/**
	 * Field labelSettingsUt.
	 */
	private JLabel labelSettingsUt = new JLabel("Impostazioni Utenti");
	/**
	 * Pannelli
	 */
	private JPanel contentPaneMain= new JPanel();
	/**
	 * Field panelMgmUt.
	 */
	private JPanel panelMgmUt = new JPanel();
	/**
	 * Field panelSettingsUt.
	 */
	private JPanel panelSettingsUt = new JPanel();
	/**
	 * Field txtOperator. static per poter far riferimento all'esterno
	 */
	public static final JTextField TXTOPERATOR = new JTextField();
	 /**
     * Riferimento a model
     */
	
	public SchermataPrincipale(String User) {
		
		/**
		 * Si rende impossibile il cambio di risoluzione della finestra
		 */
		setResizable(false);
		/**
		 * Si definisce l'icona della schermata
		 */
		setIconImage(Toolkit.getDefaultToolkit().getImage(SchermataPrincipale.class.getResource("/it/magazzinocofi/resources/apple-touch-icon.png")));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		/**
		 * Posizione e grandezza
		 */
		setBounds(100, 100, 720, 502);
		this.contentPaneMain.setBackground(Color.WHITE);
		this.contentPaneMain.setForeground(Color.BLACK);
		this.contentPaneMain.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(this.contentPaneMain);
		this.contentPaneMain.setLayout(null);

		this.lblTenarisIcon.setIcon(new ImageIcon(SchermataPrincipale.class.getResource("/it/magazzinocofi/resources/Tenaris_logo.JPG")));
		this.lblTenarisIcon.setBounds(10, 11, 369, 102);
		
		this.btnInsert.setFont(new Font("Arial", Font.BOLD, 11));
		this.btnInsert.setForeground(new Color(0,153,0));
		this.btnInsert.setBounds(54, 186, 151, 43);
		
		this.btnModification.setBounds(54, 252, 151, 43);
		this.btnModification.setFont(new Font("Arial", Font.BOLD, 11));
		this.btnModification.setForeground(ColoriTenarisPrimary.GREEN355);
		
		this.btnDisplay.setBounds(54, 319, 151, 43);
		this.btnDisplay.setFont(new Font("Arial", Font.BOLD, 11));
		this.btnDisplay.setForeground(ColoriTenarisPrimary.GREEN355);
		
		this.btnAddUt.setBounds(10, 11, 157, 44);
		this.btnAddUt.setFont(new Font("Arial", Font.BOLD, 11));
		this.btnAddUt.setForeground(ColoriTenarisPrimary.GREEN355);
		
		this.btnDropUt.setBounds(10, 78, 157, 44);
		this.btnDropUt.setFont(new Font("Arial", Font.BOLD, 11));
		this.btnDropUt.setForeground(ColoriTenarisPrimary.GREEN355);

		this.panelMgmUt.setBounds(473, 173, 180, 135);
		this.panelMgmUt.setLayout(null);
		
		this.lblMgmUt.setHorizontalAlignment(SwingConstants.CENTER);
		this.lblMgmUt.setFont(new Font("Arial", Font.BOLD, 11));
		this.lblMgmUt.setBounds(473, 148, 180, 14);

		this.lbWelcome.setFont(new Font("Arial", Font.BOLD, 11));
		this.lbWelcome.setBounds(20, 124, 72, 14);
		
		TXTOPERATOR.setFont(new Font("Arial", Font.BOLD, 11));
		TXTOPERATOR.setEditable(false);
		TXTOPERATOR.setBounds(93, 124, 86, 20);
		TXTOPERATOR.setColumns(10);
		
		panelSettingsUt.setBounds(249, 173, 180, 135);
		panelSettingsUt.setLayout(null);
		btnUpload.setBounds(10, 81, 160, 43);
		
		btnUpload.setFont(new Font("Arial", Font.BOLD, 11));
		btnUpload.setForeground(ColoriTenarisPrimary.GREEN355);
		btnPasswordModification.setBounds(10, 11, 160, 43);
		
		btnPasswordModification.setFont(new Font("Arial", Font.BOLD, 11));
		btnPasswordModification.setForeground(ColoriTenarisPrimary.GREEN355);
		
		labelSettingsUt.setHorizontalAlignment(SwingConstants.CENTER);
		labelSettingsUt.setFont(new Font("Arial", Font.BOLD, 11));
		labelSettingsUt.setBounds(249, 148, 180, 14);
		/**
		 * Aggiunte dei componenti
		 */
		contentPaneMain.add(panelMgmUt);
		contentPaneMain.add(panelSettingsUt);

		panelMgmUt.add(btnAddUt);
		panelMgmUt.add(btnDropUt);

		panelSettingsUt.add(btnUpload);
		panelSettingsUt.add(btnPasswordModification);

		contentPaneMain.add(btnInsert);
		contentPaneMain.add(lblTenarisIcon);
		contentPaneMain.add(btnModification);
		contentPaneMain.add(btnDisplay);
		contentPaneMain.add(lblMgmUt);
		contentPaneMain.add(lbWelcome);
		contentPaneMain.add(TXTOPERATOR);
		contentPaneMain.add(labelSettingsUt);
		setTXToperaTtor(User);
	}
	
	

	/**
	 * Si imposta dall'esterno il listener del bottone che richiama la finestra di Modifica Password
	 * @param log ActionListener
	 */
    public void addPasswordModificationListener(ActionListener log) {
    	btnPasswordModification.addActionListener(log);
    }
    
	/**
	 * Si imposta dall'esterno il listener del bottone che richiama la finestra di Inserimento
	 * @param log ActionListener
	 */
    public void addInsertListener(ActionListener log) {
    	btnInsert.addActionListener(log);
    }
	
	private void setTXToperaTtor(String user){
		TXTOPERATOR.setText(user);
	}
	
}
